home *** CD-ROM | disk | FTP | other *** search
/ Codemasters Artwork Disc ECTS 2000 ( UK) / Codemasters - Artwork Disc ECTS 2000 (UK).bin / pc / xtras / medial~1 / setfx~1.dir / Internal_101_Compass Object.ls < prev    next >
Encoding:
Text File  |  1998-12-01  |  3.8 KB  |  153 lines

  1. property pCompassSprite, pArrowsSprite, pTextSprite, pTextField, pCurVal, pCallBackObj, pRefcon, pRange, pMin, pMax, pCenterPoint, pActive
  2.  
  3. on new me, propList
  4.   set pCompassSprite to getaProp(propList, #lineSprite)
  5.   set pArrowsSprite to getaProp(propList, #arrowsSprite)
  6.   set pTextSprite to getaProp(propList, #textSprite)
  7.   set pTextField to getaProp(propList, #textField)
  8.   set pCenterPoint to getaProp(propList, #center)
  9.   set pMin to -720
  10.   set pMax to 720
  11.   set pCurVal to getaProp(propList, #cur)
  12.   set pRange to pMax - pMin
  13.   set pActive to getaProp(propList, #active)
  14.   set pCallBackObj to getaProp(propList, #callback)
  15.   set pRefcon to getaProp(propList, #ref)
  16.   SetVal(me, pCurVal)
  17.   SetEnabled(me, pActive)
  18.   return me
  19. end
  20.  
  21. on wait me, waitTime
  22.   set t to the ticks
  23.   repeat while the ticks < (t + waitTime)
  24.   end repeat
  25. end
  26.  
  27. on click me
  28.   if not pActive then
  29.     exit
  30.   end if
  31.   repeat while the stillDown
  32.     set x to the mouseH - the locH of sprite the clickOn
  33.     set y to the mouseV - the locV of sprite the clickOn
  34.     if x = 0 then
  35.       set x to -0.0001
  36.     end if
  37.     set a to atan(float(y) / x) + (0.5 * PI)
  38.     if x < 1 then
  39.       set a to a + PI
  40.     end if
  41.     set a to integer(a / (2 * PI) * 360)
  42.     if a > 180 then
  43.       set a to a - 360
  44.     end if
  45.     SetVal(me, a)
  46.     if objectp(pCallBackObj) then
  47.       compassChange(pCallBackObj, pRefcon, a)
  48.     end if
  49.     updateStage()
  50.   end repeat
  51.   if objectp(pCallBackObj) then
  52.     EndChange(pCallBackObj)
  53.   end if
  54. end
  55.  
  56. on Arrows me
  57.   if not pActive then
  58.     exit
  59.   end if
  60.   set h1 to the locH of the clickLoc
  61.   set h2 to the locH of sprite the clickOn
  62.   if h1 < h2 then
  63.     set side to "left"
  64.     set d to -1
  65.   else
  66.     set side to "right"
  67.     set d to 1
  68.   end if
  69.   set the member of sprite pArrowsSprite to member ("horizArrows" && side)
  70.   set newVal to max(min(pCurVal + d, pMax), pMin)
  71.   if objectp(pCallBackObj) then
  72.     compassChange(pCallBackObj, pRefcon, newVal)
  73.   end if
  74.   updateStage()
  75.   wait(me, 5)
  76.   repeat while the stillDown
  77.     if rollOver(pArrowsSprite) then
  78.       set the member of sprite pArrowsSprite to member ("horizArrows" && side)
  79.       set pCurVal to max(min(pCurVal + d, pMax), pMin)
  80.     else
  81.       set the member of sprite pArrowsSprite to member "horizArrows"
  82.     end if
  83.     SetVal(me, pCurVal)
  84.     if objectp(pCallBackObj) then
  85.       compassChange(pCallBackObj, pRefcon, newVal)
  86.     end if
  87.     wait(me, 5)
  88.   end repeat
  89.   set the member of sprite pArrowsSprite to member "horizArrows"
  90.   if objectp(pCallBackObj) then
  91.     EndChange(pCallBackObj)
  92.   end if
  93. end
  94.  
  95. on TextOut me
  96.   if the platform contains "Mac" then
  97.     set degreeSymbol to numToChar(161)
  98.   else
  99.     set degreeSymbol to numToChar(186)
  100.   end if
  101.   if voidp(pCurVal) then
  102.     put " " into field pTextField
  103.   else
  104.     put string(integer(pCurVal)) & degreeSymbol into field pTextField
  105.   end if
  106. end
  107.  
  108. on SetVal me, newVal
  109.   puppetSprite(pThumbSprite, 1)
  110.   set pCurVal to newVal
  111.   drawLine(me)
  112.   TextOut(me)
  113. end
  114.  
  115. on drawLine me
  116.   puppetSprite(pCompassSprite, 1)
  117.   set a to (float(pCurVal) / 360 * 2 * PI) - (0.5 * PI)
  118.   set x to integer(cos(a) * 14)
  119.   set y to integer(sin(a) * 14)
  120.   if (x = 1) or (x = 0) then
  121.     set x to 2
  122.   else
  123.     if x = -1 then
  124.       set x to -2
  125.     else
  126.       if (y = 1) or (y = 0) then
  127.         set y to 2
  128.       else
  129.         if y = -1 then
  130.           set y to -2
  131.         end if
  132.       end if
  133.     end if
  134.   end if
  135.   set r to rect(pCenterPoint, pCenterPoint + point(x, y))
  136.   if ((x < 0) and (y > 0)) or ((x > 0) and (y < 0)) then
  137.     set the castNum of sprite pCompassSprite to the number of member "line2"
  138.   else
  139.     set the castNum of sprite pCompassSprite to the number of member "line1"
  140.   end if
  141.   set the rect of sprite pCompassSprite to r
  142. end
  143.  
  144. on SetEnabled me, enabled
  145.   set pActive to enabled
  146.   enableInterfaceElement(pCompassSprite, enabled)
  147.   enableInterfaceElement(pArrowsSprite, enabled)
  148.   enableInterfaceElement(pTextSprite, enabled)
  149. end
  150.  
  151. on Release me
  152. end
  153.